<template>
    <div class="other-pages">
        <el-card class="box-card">
            <div slot="header">删除多余关注数据（不输入AD代表删除所有人多余数据）:</div>
            <el-form size="small" :inline="true" class="demo-form-inline">                
                <el-form-item label="人员AD：">
                    <el-input
                        v-model="formInline1.ad"
                        @keyup.enter.native="startimplement(1,'删除多余关注数据')"
                        placeholder="请输入人员AD"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="startimplement(1,'删除多余关注数据')">执行</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="box-card">
            <p slot="header">修改代理数据 (不输入AD代表修改所有人多余数据):</p>
            <el-form size="small" :inline="true" class="demo-form-inline">
                <el-form-item label="人员AD：">
                    <el-input
                        v-model="formInline2.ads"
                        @keyup.enter.native="startimplement(2,'修改代理数据')"
                        placeholder="请输入人员AD"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="startimplement(2,'修改代理数据')">执行</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="box-card">
            <p slot="header">同步人员信息数据:</p>
            <el-form size="small" :inline="true" class="demo-form-inline">
            <el-form-item label="人员AD(不输入代表删除所有人多余数据)：">
                <el-input
                    v-model="formInline3.ads"
                    @keyup.enter.native="startimplement(3,'同步人员信息数据')"
                    placeholder="请输入人员AD"
                ></el-input>
            </el-form-item>
                <el-form-item label="部门名称(不输入代表所有部门)：">
                <el-input
                    v-model="formInline3.dept"
                    @keyup.enter.native="startimplement(3,'同步人员信息数据')"
                    placeholder="请输入部门名称："
                ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="startimplement(3,'同步人员信息数据')">执行</el-button>
            </el-form-item>
            </el-form>
        </el-card>
         <el-card class="box-card">
             <p slot="header">打卡地址数据补充：</p>
             <el-form size="small" :inline="true" class="demo-form-inline">
                <el-form-item label="人员AD(不输入代表所选日期所有人的数据)：">
                    <el-input
                        v-model="formInline4.ads"
                        @keyup.enter.native="startimplement(4,'补充打卡地址数据')"
                        placeholder="请输入人员AD"
                    ></el-input>
                </el-form-item>
                <el-form-item label="日期（默认当天）：">
                    <el-date-picker
                        v-model="formInline4.date"
                        type="date"
                        placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="startimplement(4,'补充打卡地址数据')">执行</el-button>
                </el-form-item>
             </el-form>
        </el-card>
        <loading-tost :loading="loading"></loading-tost>
    </div>
</template>
<script>
import Vue from "vue";
import LoadingTost from '@/components/public/loading-tost'
import { Card , Form , FormItem , DatePicker} from "element-ui";
import { attentionDeleteApi , proxySyncApi , synchronizeApi , positionCheckApi} from "@/api/getData";
import { setTimeout } from 'timers';
Vue.use(Card);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(DatePicker);
export default {
    name:"OtherPage",
    components:{
        "loading-tost":LoadingTost
    },
    data(){
        return {
            loading:false,
            formInline1:{ad:""},
            formInline2:{ads:""},
            formInline3:{ads:"",dept:""},
            formInline4:{ads:"",date:""},
        }
    },
    methods:{
        startimplement(type,text){
            this.$confirm(`此操作将${text}, 是否继续?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.loading = true;
                // 防止请求失败
                setTimeout(()=>{
                    this.loading = false;
                },16 * 1000)
                if(type === 1){
                    this.deletItemData();
                }
                if(type === 2){
                    this.updataProxyfun();
                }
                if(type === 3){
                    this.updateuserData();
                }
                if(type === 4){
                    this.initPositionData();
                }
                
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });          
            });
        },
        async deletItemData(){
            try {
                let data = await attentionDeleteApi(this.formInline1);
                this.loading = false;
                if(data == 1){
                    this.$message({
                        type: 'success',
                        message: '执行成功!'
                    });
                }else{
                   this.$message({
                        message: '执行失败!'
                   });
                }
            } catch (error) {
                this.loading = false;
                console.log(error)
            }
        },
        async updataProxyfun(){
            try {
                let data = await proxySyncApi(this.formInline2);
                this.loading = false;
                if(data == 1){
                    this.$message({
                        type: 'success',
                        message: '执行成功!'
                    });
                }else{
                    this.$message({
                        message: '执行失败!'
                    });
                }
            } catch (error) {
                this.loading = false;
                console.log(error)
            }
        },
        async updateuserData(){
            try {
                let data = await synchronizeApi(this.formInline3);
                this.loading = false;
                if(data){
                    this.$message({
                        type: 'success',
                        message: '执行成功!'
                    });
                }else{
                   this.$message({
                        message: '执行失败!'
                   });
                }
            } catch (error) {
                this.loading = false;
                console.log(error)
            }
        },
        async initPositionData(){
            try {
                let data = await positionCheckApi(this.formInline4);
                this.loading = false;
                if(data == 1){
                    this.$message({
                        type: 'success',
                        message: '执行成功!'
                    });
                }else{
                    this.$message({
                        message: '执行失败!'
                    });
                }
            } catch (error) {
                this.loading = false;
                console.log(error)
            }
        }
    },
}
</script>
<style lang="less" scoped>
@import url('./less/otherpage.less');
</style>